package com.ybt.heartratem.common.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ybt.heartratem.R;

import java.util.List;

public class CustomSpinnerAdapter extends ArrayAdapter<String> {

    private Context mContext;
    private int mResource;
    private List<String> mData;
    private LayoutInflater mInflater;

    public CustomSpinnerAdapter(Context context, int resource, List<String> data) {
        super(context, resource, data);
        mContext = context;
        mResource = resource;
        mData = data;
        mInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(mResource, parent, false);
        }
        TextView textView = convertView.findViewById(R.id.text1);
        textView.setText(mData.get(position));
        return convertView;
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(mResource, parent, false);
        }
        TextView textView = convertView.findViewById(R.id.text1);
        textView.setText(mData.get(position));
        return convertView;
    }
}